#pragma once


#include <mutex>
#include "ShmQueueManager.hpp"



class DataStructureManager {
public:
    enum ShmDataStructureType {
        FUNC_NULL = 0,
        QUEUE = 1,
    };
public:
    // 获取单例实例的函数
    static DataStructureManager* GetInstance() {
        if (_instance == nullptr) {
            std::lock_guard<std::mutex> lock(_mutex);
            if (_instance == nullptr) {
                _instance = new DataStructureManager();

                LOG_CYC(NORMAL, "创建 DataStructureManager 实例", nullptr);
            }
        }
        return _instance;
    }

    // 销毁单例实例的函数
    static void DestroyInstance() {
        std::lock_guard<std::mutex> lock(_mutex);
        if (_instance != nullptr) {
            delete _instance;
            _instance = nullptr;

            LOG_CYC(NORMAL, "销毁 DataStructureManager 实例", nullptr);
        }
    }

public:
    void Execute(ShmMessageNode*& mesNode) {
        switch (mesNode->GetDataStructureBlock()._dataStructureType) {
            case QUEUE:
                LOG_CYC(NORMAL, "进入Queue", nullptr);
                GetQueueManager()->Execute(mesNode);
                break;

            default:
                LOG_CYC(WARNING, "消息节点返回空功能类型", nullptr);
                break;
        }
    }


private:

    ShmQueueManager*& GetQueueManager() {
        if (_shmQueueManager == nullptr)
            _shmQueueManager = ShmQueueManager::GetInstance();

        return _shmQueueManager;
    }



private:
    // 私有构造函数和析构函数
    DataStructureManager() = default;
    ~DataStructureManager() = default;

    // 删除拷贝构造函数和拷贝赋值运算符
    DataStructureManager(const DataStructureManager&) = delete;
    DataStructureManager& operator=(const DataStructureManager&) = delete;

    // 删除移动构造函数和移动赋值运算符
    DataStructureManager(DataStructureManager&&) = delete;
    DataStructureManager& operator=(DataStructureManager&&) = delete;

    // 静态成员变量，用于保存单例实例
    static DataStructureManager* _instance;
    static std::mutex _mutex;

private:
    ShmQueueManager* _shmQueueManager = nullptr;
};

// 静态成员变量的定义
DataStructureManager* DataStructureManager::_instance = nullptr;
std::mutex DataStructureManager::_mutex;